package com.ruoyi.womp.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.womp.domain.WompSpareParts;
import com.ruoyi.womp.service.IWompSparePartsService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 备件信息Controller
 * 
 * @author mzz
 * @date 2023-05-11
 */
@Controller
@RequestMapping("/womp/spareParts")
public class WompSparePartsController extends BaseController
{
    private String prefix = "womp/spareParts";

    @Autowired
    private IWompSparePartsService wompSparePartsService;

    @RequiresPermissions("womp:spareParts:view")
    @GetMapping()
    public String spareParts()
    {
        return prefix + "/spareParts";
    }

    /**
     * 查询备件信息列表
     */
    @RequiresPermissions("womp:spareParts:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(WompSpareParts wompSpareParts)
    {
        startPage();
        List<WompSpareParts> list = wompSparePartsService.selectWompSparePartsList(wompSpareParts);
        return getDataTable(list);
    }

    /**
     * 导出备件信息列表
     */
    @RequiresPermissions("womp:spareParts:export")
    @Log(title = "备件信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WompSpareParts wompSpareParts)
    {
        List<WompSpareParts> list = wompSparePartsService.selectWompSparePartsList(wompSpareParts);
        ExcelUtil<WompSpareParts> util = new ExcelUtil<WompSpareParts>(WompSpareParts.class);
        return util.exportExcel(list, "备件信息数据");
    }

    /**
     * 新增备件信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存备件信息
     */
    @RequiresPermissions("womp:spareParts:add")
    @Log(title = "备件信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(WompSpareParts wompSpareParts)
    {
        return toAjax(wompSparePartsService.insertWompSpareParts(wompSpareParts));
    }

    /**
     * 修改备件信息
     */
    @RequiresPermissions("womp:spareParts:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        WompSpareParts wompSpareParts = wompSparePartsService.selectWompSparePartsById(id);
        mmap.put("wompSpareParts", wompSpareParts);
        return prefix + "/edit";
    }

    /**
     * 修改保存备件信息
     */
    @RequiresPermissions("womp:spareParts:edit")
    @Log(title = "备件信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(WompSpareParts wompSpareParts)
    {
        return toAjax(wompSparePartsService.updateWompSpareParts(wompSpareParts));
    }

    /**
     * 删除备件信息
     */
    @RequiresPermissions("womp:spareParts:remove")
    @Log(title = "备件信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(wompSparePartsService.deleteWompSparePartsByIds(ids));
    }
}
